<template>
	<view>
		<view class="" v-if="JSON.stringify(confirm) !== '{}'">
		  <approverMsg :value="confirm"></approverMsg>			
		</view>
		<navigator class="left_box" v-if='banquet.order_id' :url="'/pages/order/detail/detail?order_id='+this.banquet.order_id">
			<text>查看定单详情</text>
		</navigator>
		<view class="hotelService"  >
			<view class="title">
				<text class="name">婚宴基本信息</text>							
			</view>
			<view class="content">
				<view class="box">
					<text>订单所属公司</text>							
					<picker :disabled="isEdit" @change="chooseBanquet"  range-key="title" :range="companyList">
					    <view class="choose"  v-if="companyList.length>1">
							 <text :class="Banquet_companyIndex!==''?'active':''">{{Banquet_companyIndex===''?'请选择':companyList[Banquet_companyIndex].title}}</text>
							 <image v-if="Banquet_companyIndex===''" src="../../../static/images/right.png" mode=""></image>
					    </view>
					</picker>
					<icon class="icon" v-if="Banquet_companyIndex!==''" type="clear" size="22upx"  @click="deleteCompany"></icon>
				</view>
				<view class="box">
					<text>婚宴总金额</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.banquet_totals"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>优惠金额</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.banquet_discount"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>桌数</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.table_amount"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>餐标</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.table_price"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>服务费总计</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.service_fee"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>酒水费用</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.wine_fee"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>加菜换菜</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.banquet_update_table"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>选择仪式</text>
					<picker @change="chooseRite" :disabled="isEdit"  range-key="title" :range="ritualList">
					    <view class="choose" >
							 <text :class="riteIndex!==''?'active':''">{{riteIndex===''?'请选择':banquet.banquet_ritual_text}}</text>
							 <image v-if="riteIndex===''" src="../../../static/images/right.png" mode=""></image>
					    </view>
						
					</picker>
					<icon class="icon" v-if="riteIndex!==''" type="clear" size="22upx"  @click="deleteRite"></icon>
				</view>
				<view class="box">
					<text>仪式价格</text>
					<input :disabled="isEdit" type="digit" v-model="banquet.banquet_ritual_hall"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="box">
					<text>其他</text>
					<input :disabled="isEdit" type="text" v-model="banquet.banquet_other"  placeholder="请输入" placeholder-style="color:#999999;" />
				</view>
				<view class="remark">
					<text>备注</text>
					<textarea :disabled="isEdit" type="text" v-model="banquet.banquet_remark" placeholder="请输入备注" placeholder-style="color:#999999;" />
				</view>
			</view>
		</view>
		
		<!-- 审核流程 -->
		<auditProcess :value="confirmList" :btnValue="buttons" :isShowBtn="options.api?false:true" @resubmit='resubmits'></auditProcess>	
		<button type="default" class="order_btn" @click="saveFn()" v-if="options.api"> 保存</button>
		
		
	</view>
</template>

<script>
	
	import approverMsg from "@/component/approverMsg.vue";//审核流程	
	import auditProcess from "@/component/auditProcess.vue";//审核流程
	import selectBox from "@/component/selectBox.vue"
	import timeSelector from '@/component/wing-time-selector/wing-time-selector.vue';
	import navigation from "@/component/navigation.vue"
	import sun from '@/utils/sun.js'
	export default {
		components: {
			navigation,
			timeSelector,
			selectBox,
			approverMsg,
			auditProcess
		},
		data() {
			return {
				isEdit:false,//是否可以编辑
				options:'',
				
				banquet:{
					banquet_totals:"",//婚宴总金额
				    table_amount:"",//桌数
				    table_price:"",//餐标
				    service_fee:"",//服务费总计
				    wine_fee:"",//酒水费用
				    banquet_update_table:"",//加菜换菜
				    banquet_ritual_hall:"",//仪式价格
				    banquet_other:"",//其他
				    banquet_remark:"",//备注
					ritual_text:'',
					ritual_id:'',
					banquet_discount:'',//优惠金额
					
				}, // 婚宴
				Banquet_companyIndex:'',
				riteIndex:'',
				companyList:[],
				ritualList:[],
				confirmList:'',//
				confirm:{},//审批信息
				buttons:'',//是当前审核可以有的按钮
			};
		},
		onLoad(options) {
			//审核查看
			if(options.lookApproval){
				this.options= JSON.parse(options.lookApproval)
				this.isEdit =true;
				//查看信息
				this.getDetail(this.options)	
			}	
			if(options.params){
				this.options= JSON.parse(options.params);
				this.getData(this.options)
			}
			//查看
			if(options.id){				
			   this.options= options;
			   this.isEdit =true;
			   //查看信息
			   this.getDetail(this.options)			 
			}
		},
		methods:{
			//获取查看信息
			getDetail(e){
			  let that=this										
			  sun.request({
				url: '/h5/order.confirm/detail',
				showLoading: true,
				token:true,
				data:{
					id:e.id,
					type:e.user?'confirm_user':'',
				},
				success(res) {				
					if(res.code==200){			
					   that.editApi=res.data.editApi;
					   that.banquet=res.data.detail.banquet;	
					   that.confirmList=res.data.confirmList;
					   that.confirm=res.data.confirm;//代表的是当前审核的信息
					   that.buttons=res.data.buttons;
					   //判断是否可以编辑
					   that.buttons.map((item,index)=>{
						   if(item.id=='update'){
							   that.isEdit = false;
						   }
					   })
					   
					   that.companyList=res.data.companyList?res.data.companyList:''
					   that.companyList.map((item,index)=>{						   
						   if(item.id==that.banquet.company_id){
							   that.Banquet_companyIndex=index;
							   that.banquet.company_title=item.title
						   }
					   })
					   that.ritualList=res.data.ritualList?res.data.ritualList:''
					   that.ritualList.map((item,index)=>{						   
						   if(item.id==that.banquet.banquet_ritual_id){
							   that.riteIndex=index;
							   that.banquet.banquet_ritual_text=item.title
						   }
					   })
					}
				},
				fail(e) {
					uni.showToast({
						icon: "none",
						title: "服务器开小差去啦~",
					})
				}
			  })						 
			},
			getData(e){
			  let that=this										
			  sun.request({
				url: e.read,
				showLoading: true,
				token:true,
				data:{
					order_id:e.order_id
				},
				success(res) {				
					if(res.code==200){								 
					    that.companyList = res.data.companyList?res.data.companyList:'';						
						// that.packageList=res.data.packageList?res.data.packageList:''						
						that.ritualList=res.data.ritualList?res.data.ritualList:''
					    that.confirmList=res.data.confirmList?res.data.confirmList:''
					}
				},
				fail(e) {
					uni.showToast({
						icon: "none",
						title: "服务器开小差去啦~",
					})
				}
			  })						 
			},
			//婚宴 所属公司
			chooseBanquet(e){
				this.Banquet_companyIndex=e.target.value
				this.banquet.company_id = this.companyList[this.Banquet_companyIndex].id;
				this.banquet.company_title = this.companyList[this.Banquet_companyIndex].title;				
			},
			deleteCompany(){
				this.Banquet_companyIndex=''
				this.banquet.company_id=''
			},
			//选择婚宴仪式
			chooseRite(e){				   
					 this.riteIndex=e.target.value
					 this.banquet.banquet_ritual_text = this.ritualList[this.riteIndex].title;
					 this.banquet.banquet_ritual_id = this.ritualList[this.riteIndex].id;					 
				},
			//删除婚宴仪式
			deleteRite(){
				this.riteIndex=''; //合作模式
			},
			// 编辑提交
			editFn(api,id){
				let that=this;
				sun.request({
					url: api,
					showLoading: true,
					token:true,
					data:{
						order_confirm_id:that.options.id,
						id:id?id:'',
						banquet:that.banquet?JSON.stringify(that.banquet):'',																	
					},
					success(res) {
					  if(res.code==200){							
							uni.redirectTo({
							 	url:"/pages/order/index"	
							})
							uni.showToast({
								icon:"none",
								title:res.msg
							})										
					  }else{
							 uni.showToast({
								icon:"none",
								title:res.msg
							 })	
					  }
					}
				})
			},
			//提交审核
			saveFn(){			    
				let that=this;			
				sun.request({
					url: that.options.api,
					showLoading: true,
					token:true,
					data:{	
						order_id:that.options.order_id,						
						banquet:that.banquet?JSON.stringify(that.banquet):'',												
					},
					success(res) {
					  if(res.code==200){							
							uni.redirectTo({
							 	url:"/pages/order/index"	
							})
							uni.showToast({
								icon:"none",
								title:res.msg
							})										
					  }else{
							 uni.showToast({
								icon:"none",
								title:res.msg
							 })	
					  }
					}
				})
			},
			//底部评论按钮
			resubmits(item){				
				if(item.label=='同意'||item.label=='拒绝'||item.label=='评论'){
					this.commentFn(item)
				}else if(item.label == '转交'){
					uni.navigateTo({
						url: '../../../component/search/search?type=' + 'changeUser'
					})
				}else{
				   this.editFn(item.api,item.id)	
				}
								
			},
			// 编辑提交
			commentFn(e){
				let that=this;
				sun.request({
					url: e.api,
					showLoading: true,
					token:true,
					data:{						
						id:that.options.id?that.options.id:'',						
						content:e.content?e.content:'',
						image:e.image?e.image:'',
					},
					success(res) {
					  if(res.code==200){													
							uni.showToast({
								icon:"none",
								title:res.msg
							})
			               that.getDetail(that.options)																	
					  }else{
							 uni.showToast({
								icon:"none",
								title:res.msg
							 })	
					  }
					}
				})
			},
		}
	}
</script>

<style lang="less">
@import '../common.less';
</style>
